﻿using AntdUI;
using BST250301TestStand.Models;
using BST250301TestStand.Models.Helpers;
using BST250301TestStand.Models.Utils;
using CsvHelper;
using MathNet.Numerics.Distributions;
using Mysqlx.Crud;
using NPOI.HPSF;
using NPOI.SS.Formula.Functions;
using NPOI.SS.Formula.PTG;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.UserModel; // 用于 .xlsx 文件
using Org.BouncyCastle.Asn1;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using static Azure.Core.HttpHeader;
using static BST250301TestStand.Models.Utils.ZDBC;
using static System.ComponentModel.Design.ObjectSelectorEditor;

namespace BST250301.Views
{
    public partial class ReportShow : Form
    {
        AntList<RecordData> antList = new AntList<RecordData>();
        public ReportShow(string planname, string templatename, string sn, DateTime dt)
        {
            InitializeComponent();
            InitTableColumns();
            InitData(planname, templatename, sn, dt);
        }

        private async void InitData(string planname, string templatename, string sn, DateTime dt)
        {
            this.selectProject.Text = planname;
            this.selectSubPlan.Text = templatename;
            this.inputSN.Text = sn;

            this.selectProject.Enabled = false;
            this.selectSubPlan.Enabled = false;
            this.selectProject.Enabled = false;
            this.inputSN.Enabled = false;
            antList = await GetReport(planname, templatename, sn, dt);
            if (antList != null && antList.Count > 0)
            {
                table_base.Binding(antList);
                table_base.Bordered = true;
            }
            else
            {
                this.label1.Text = "未查询到相关测试数据！";
            }
        }
        private void InitTableColumns()
        {
            table_base.Columns = new ColumnCollection() {
                new AntdUI.Column("ID", "记录ID",ColumnAlign.Center){ Width ="50"},
                new AntdUI.Column("ProjectDT","测试时间"),
                new AntdUI.Column("PlanName","方案名称"),
                new AntdUI.Column("SubPlanName","项目模板"),
                new AntdUI.Column("ProjectName","测试项目"),
                new AntdUI.Column("ProductSN","产品SN"),
                new AntdUI.Column("ProductTimes","测试次第"),
                new AntdUI.Column("Name","数据名"),
                new AntdUI.Column("DefaultValue","标准值"),
                new AntdUI.Column("ReadValue","取值"),
                new AntdUI.Column("ReadAVG","取值均值"),
                new AntdUI.Column("ReadMax","取值最大值"),
                new AntdUI.Column("ReadMin","取值最小值"),
                new AntdUI.Column("QC","评判"),
                new AntdUI.Column("Note","备注"),
            };
            table_base.Bordered = true;
        }
        private async Task<AntList<RecordData>> GetReport(string plan, string subplan, string sn, DateTime? dtstart)
        {
            return DB.GetResultParameters(plan, subplan, sn, dtstart);

        }
    }
}
